//
//  MarketingPHBTableViewCell.m
//  ZhuiKe55like
//
//  Created by junseek on 16/5/16.
//  Copyright © 2016年 五五来客 李江. All rights reserved.
//

#import "MarketingPHBTableViewCell.h"

@interface MarketingPHBTableViewCell (){
    //
  
    UIImageView *userLogo;
    UILabel *lblName;
    UILabel *lblnum;
    
    UIImageView *imageNum;
    
    NSIndexPath *tempIndexPath;
    NSDictionary *tempDic;
    UIView *BGV;
}


@end

@implementation MarketingPHBTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor=[UIColor clearColor];
        BGV=[[UIView alloc]initWithFrame:self.bounds];
        [self setBackgroundView: BGV];
            
        userLogo=[RHMethods imageviewWithFrame:CGRectMake(10, 10, 40, 40) defaultimage:@""];
        userLogo.userInteractionEnabled=NO;
        userLogo.layer.masksToBounds = YES;
        // 其實就是設定圓角，只是圓角的弧度剛好就是圖片尺寸的一半
        userLogo.layer.cornerRadius =(W(userLogo))/2.0;
        //边框
        userLogo.layer.borderWidth=0.1;
        userLogo.layer.borderColor =[[UIColor clearColor] CGColor];
        [self addSubview:userLogo];
        
        lblName=[RHMethods labelWithFrame:CGRectMake(XW(userLogo)+10, 20, 0, 20) font:Font(16) color:rgbTitleColor text:@" "];//
        [self addSubview:lblName];
    
        
        lblnum=[RHMethods labelWithFrame:CGRectMake(kScreenWidth-35, 20, 20, 20) font:Font(13) color:RGBCOLOR(255, 255, 255) text:@""];
        lblnum.tag=102;
        lblnum.backgroundColor=[UIColor whiteColor];
        [lblnum setTextAlignment:NSTextAlignmentCenter];
        [self addSubview:lblnum];
    
        imageNum=[RHMethods imageviewWithFrame:CGRectMake(kScreenWidth-45, 0, 45, 60) defaultimage:@"" contentMode:UIViewContentModeCenter];
        [self addSubview:imageNum];
        
        [self addSubview:[RHMethods imageviewWithFrame:CGRectMake(0, 59.5, kScreenWidth, 0.5) defaultimage:@"userLine"] ];
            
        
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    return self;
}

//内容更新
-(void)setValueForDictionary:(NSDictionary *)dic indexPath:(NSIndexPath *)indexPath type:(NSString *)strType{
    tempIndexPath=indexPath;
    tempDic=dic;
    [userLogo imageWithURL:[dic valueForJSONStrKey:@"path"] useProgress:NO useActivity:NO];
    
    if ([[dic valueForJSONStrKey:@"id"]isEqualToString:[[Utility Share] userId]]) {
        [BGV setBackgroundColor:rgbpublicColor];
    }else{
        [BGV setBackgroundColor:RGBCOLOR(255, 255, 255)];
    }
       //
    
    
    
    lblName.textColor=[[dic valueForJSONStrKey:@"id"]isEqualToString:[[Utility Share] userId]]?[UIColor whiteColor]:rgbTitleColor;
    lblName.text=[dic valueForJSONStrKey:@"name"];
    lblName.frameWidth=[lblName sizeThatFits:CGSizeMake(MAXFLOAT, 20)].width;
    if (W(lblName)>kScreenWidth-170) {
        lblName.frame=CGRectMake(X(lblName), Y(lblName), kScreenWidth-170, H(lblName));
    }
    
   
    
    lblnum.text=[NSString stringWithFormat:@"%ld",indexPath.row+1];
//    if ([[dic valueForJSONStrKey:@"id"]isEqualToString:[[Utility Share] userId]] && [[dic valueForJSONStrKey:@"myrank"] notEmptyOrNull]) {
//        lblnum.text=[dic valueForJSONStrKey:@"myrank"];
//    }
    float fw_t=([lblnum sizeThatFits:CGSizeMake(MAXFLOAT, 20)].width+12);
    fw_t=fw_t<20?20:fw_t;
    fw_t=fw_t>60?60:fw_t;
    lblnum.frame=CGRectMake((kScreenWidth-60)+ ((60- fw_t)/2.0>0?(60- fw_t)/2.0:0), Y(lblnum), fw_t, 20);
   
    if (indexPath.row<3) {
        lblnum.hidden=YES;
        imageNum.hidden=NO;
        imageNum.center=lblnum.center;
        imageNum.image=[UIImage imageNamed:[NSString stringWithFormat:@"phbno%ld",indexPath.row+1]];
//        [[Utility Share] viewLayerRound:lblnum borderWidth:2.0 borderColor:RGBCOLOR(228, 18, 28)];
//        lblnum.textColor=RGBCOLOR(228, 18, 28);
    }else{
        imageNum.hidden=YES;
        lblnum.hidden=NO;
        [[Utility Share] viewLayerRound:lblnum borderWidth:2.0 borderColor:RGBCOLOR(100, 100, 100)];
        lblnum.textColor=RGBCOLOR(100, 100, 100);
    }
    
    if ([[dic valueForJSONStrKey:@"id"]isEqualToString:[[Utility Share] userId]]) {
        lblnum.textColor=rgbRedColor;
        [[Utility Share] viewLayerRound:lblnum borderWidth:2.0 borderColor:[UIColor whiteColor]];
    }

    
    
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
